Skip to content

Fix concurrent function stats drop race#46

Draft
NikolayS wants to merge 1 commit into
masterfrom
bug19520-pgstat-drop-race-github
Draft

Fix concurrent function stats drop race#46
NikolayS wants to merge 1 commit into
masterfrom
bug19520-pgstat-drop-race-github

Conversation

@NikolayS

Copy link
Copy Markdown
Owner

Fixes the pgstats side of BUG #19520, where a stale concurrent function/procedure call can create and drop a function stats entry for an already-dropped procedure OID while the DROP transaction is still in post-commit stats cleanup.

Before this change, the second drop of the same shared stats entry raised:

ERROR: trying to drop stats entry already dropped: kind=function ...

When that ERROR happened after RecordTransactionCommit(), xact abort handling escalated to:

PANIC: cannot abort transaction ..., it was already committed

This patch makes duplicate drops of an already-dropped shared stats entry behave like "not freed yet" rather than ERRORing, so normal pgstat entry-ref GC can finish the cleanup. The stale function-call path also requests that GC when its stats drop cannot free immediately.

The test adds injection points to deterministically schedule the race:

  • stale CALL proc_test() resolves the procedure OID and waits before function stats init
  • concurrent DROP PROCEDURE proc_test() waits in post-commit function stats cleanup
  • stale CALL creates/drops function stats for the removed OID while another session holds a local stats ref
  • DROP cleanup attempts the duplicate stats drop

Validation:

  • Temporarily restoring the old elog(ERROR) reproduces the original ERROR -> COMMIT-state abort warning -> PANIC path in the new isolation spec.
  • meson setup build -Dinjection_points=true -Dcassert=true
  • ninja -C build
  • meson test -C build --suite setup --print-errorlogs
  • env PG_TEST_TIMEOUT_DEFAULT=60 meson test -C build 'injection_points/isolation' 'injection_points/regress' --print-errorlogs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant